<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","project_id");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_project.php";
$FileTemplate  = "ais_transaction_project_list.html";
$TableName     = "tblproject";
$SubHeaderTitle= "Prospect List";
$PageSize      = 10 ;
$HTMLGridList  = "ToolGrid";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$projName = GetParam("projName","");
$projLoc = GetParam("projLoc","");
$projOwn = GetParam("projOwn","");



//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `$TableName` as a 
        LEFT JOIN tblprojectgroup as b ON a.project_group_id = b.project_group_id  ";

if ($projName) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.project_name like '%".$projName."%'";
	else $WHERE .= " a.project_name like '%".$projName."%'";	

if ($projLoc) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.project_location like '%".$projLoc."%'";
	else $WHERE .= " a.project_location like '%".$projLoc."%'";
	
if ($projOwn) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.project_owner like '%".$projOwn."%'";
	else $WHERE .= " a.project_owner like '%".$projOwn."%'";

if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	else $WHERE = " WHERE 1 ";

$SQL = $SQL.$WHERE." ORDER BY a.project_id DESC";



$WHERE = "";

$SQLCount = "SELECT count(*) FROM `$TableName` as a 
        LEFT JOIN tblprojectgroup as b ON a.project_group_id = b.project_group_id  ";

if ($projName) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.project_name like '%".$projName."%'";
	else $WHERE .= " a.project_name like '%".$projName."%'";	

if ($projLoc) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.project_location like '%".$projLoc."%'";
	else $WHERE .= " a.project_location like '%".$projLoc."%'";
	
if ($projOwn) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.project_owner like '%".$projOwn."%'";
	else $WHERE .= " a.project_owner like '%".$projOwn."%'";

if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	else $WHERE = " WHERE 1 ";

$SQLCount = $SQLCount.$WHERE." ORDER BY a.project_id DESC";


//Select Department 
//$SQLDept = "SELECT * FROM tbldept";

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
//$TBS->MergeBlock("deptblk",$DBMysql,$SQLDept);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName,$TableName;	
	for ($x=1;$x<=$PageSize;$x++) {				
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("$TableName",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>
